package com.example.hhhh;

import android.content.Context;
import android.graphics.drawable.BitmapDrawable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.PopupWindow;

/**
 * @ProjectName: Hhhh
 * @Package: com.example.hhhh
 * @ClassName: Popdemo
 * @Description: java类作用描述
 * @Author: songhua
 * @CreateDate: 2020/1/9 0009 10:55
 */
public class Popdemo extends PopupWindow implements  View.OnClickListener {
    private float density = 1.0f;
    private Context mContext;

    public Popdemo(Context context) {
        super(context);
        mContext=context;
        initPopupWindow();
        View view =   View.inflate(context, R.layout.popdemo, null);
        setContentView(view);
        //设置popwindow的宽高，这个数字是多少就设置多少dp，注意单位是dp
        setHeight((int)   (160*density));
        setWidth((int) (100*density));
    }



    //初始化popwindow
    private void initPopupWindow() {
//        setAnimationStyle(R.style.popwindowAnim);//设置动画
        setFocusable(true);
        setOutsideTouchable(true);
        setBackgroundDrawable(new BitmapDrawable());
        density =   mContext.getResources().getDisplayMetrics().density;//
    }

    /**
     * 显示popupWindow
     */
    public void showPopupWindow(View   parent) {
        if (!this.isShowing())   {
            // 以下拉方式显示popupwindow
            this.showAsDropDown(parent, parent.getLayoutParams().width / 2,   18);
        } else {
            this.dismiss();
        }
    }

    @Override
    public void onClick(View v)   {
        //自己设置点击事件。。。
    }
}


